package com.galaxy.product.controller;

import com.galaxy.common.core.domain.R;
import com.galaxy.common.mybatis.core.page.PageQuery;
import com.galaxy.common.mybatis.core.page.TableDataInfo;
import com.galaxy.product.domain.ProductDetail;
import com.galaxy.product.domain.bo.ProductDetailBo;
import com.galaxy.product.domain.vo.ProductDetailVo;
import com.galaxy.product.service.IProductDetailService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 商品详情Controller
 *
 * @author GalaxyMart
 */
@Tag(name = "商品详情管理")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/detail")
public class ProductDetailController {

    private final IProductDetailService productDetailService;

    /**
     * 查询商品详情列表
     */
    @Operation(summary = "查询商品详情列表")
    @GetMapping("/list")
    public TableDataInfo<ProductDetailVo> list(ProductDetailBo productDetail, PageQuery pageQuery) {
        return productDetailService.queryPageList(productDetail, pageQuery);
    }

    /**
     * 获取商品详情详细信息
     */
    @Operation(summary = "获取商品详情详细信息")
    @GetMapping("/{id}")
    public R<ProductDetail> getInfo(@PathVariable("id") Long id) {
        return R.ok(productDetailService.getById(id));
    }

    /**
     * 根据商品ID获取商品详情
     */
    @Operation(summary = "根据商品ID获取商品详情")
    @GetMapping("/product/{productId}")
    public R<ProductDetail> getByProductId(@PathVariable("productId") Long productId) {
        return R.ok(productDetailService.selectByProductId(productId));
    }

    /**
     * 获取商品详情详细信息
     */
    @GetMapping("/byProductId/{productId}")
    public R<ProductDetail> getInfoByProductId(@PathVariable Long productId) {
        return R.ok(productDetailService.getInfoByProductId(productId));
    }

    /**
     * 新增商品详情
     */
    @Operation(summary = "新增商品详情")
    @PostMapping
    public R<Boolean> add(@Validated @RequestBody ProductDetail productDetail) {
        return R.ok(productDetailService.insertProductDetail(productDetail));
    }

    /**
     * 修改商品详情
     */
    @Operation(summary = "修改商品详情")
    @PutMapping
    public R<Boolean> edit(@Validated @RequestBody ProductDetail productDetail) {
        return R.ok(productDetailService.updateProductDetail(productDetail));
    }

    /**
     * 删除商品详情
     */
    @Operation(summary = "删除商品详情")
    @DeleteMapping("/{id}")
    public R<Boolean> remove(@PathVariable Long id) {
        return R.ok(productDetailService.deleteProductDetailById(id));
    }
}
